package com.tanqidi.arcgisandroid.wkt;


import com.esri.arcgisruntime.geometry.Polygon;

import org.gdal.ogr.Geometry;
import org.gdal.ogr.ogr;

public class ExportWktJavaDemo {


    public String geometryCoverWktTxt(Polygon polygon){

        // 注册所有的驱动
        ogr.RegisterAll();

        Geometry gdalGeometry = new Geometry(ogr.wkbPolygon);
        Geometry ring = new Geometry(ogr.wkbLinearRing);
        //将arcgis的geometry转成gdal的geometry
        polygon.getParts().forEach(immutablePart -> {
            immutablePart.getPoints().forEach(point -> {
                ring.AddPoint_2D(point.getX(), point.getY());
            });
        });
        gdalGeometry.AddGeometry(ring);
        gdalGeometry.CloseRings();

        String wktText = gdalGeometry.ExportToWkt();
        return wktText;

    }

}
